"use strict";

// 密码加密
const bcrypt = require("bcryptjs");
// 格式化时间
const dayjs = require("dayjs");
dayjs.locale("zh-cn");

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.bulkInsert(
      "Users",
      [
        {
          email: "admin@clwy.cn",
          username: "admin",
          password: bcrypt.hashSync("123123", 10),
          nickname: "超级管理员",
          sex: 2,
          role: 100,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: "user1@clwy.cn",
          username: "user1",
          password: bcrypt.hashSync("123123", 10),
          nickname: "普通用户1",
          sex: 0,
          role: 0,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: "user2@clwy.cn",
          username: "user2",
          password: bcrypt.hashSync("123123", 10),
          nickname: "普通用户2",
          sex: 0,
          role: 0,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: "user3@clwy.cn",
          username: "user3",
          password: bcrypt.hashSync("123123", 10),
          nickname: "普通用户3",
          sex: 1,
          role: 0,
          createdAt: new Date(),
          updatedAt: new Date(),
        },
        {
          email: 'member@clwy.cn',
          username: 'member',
          password: bcrypt.hashSync('123123', 10),
          nickname: '大会员用户',
          sex: 1,
          role: 1,
          membershipExpiredAt: dayjs().add(1, 'year').toDate(),
          createdAt: new Date(),
          updatedAt: new Date()
        },
      ],
      {}
    );
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.bulkDelete("Users", null, {});
  },
};
